package model.container;

import javax.swing.*;
import java.util.HashMap;

/**
 * Created by IntelliJ IDEA.
 * User: QIUKX of Freshpower.com.cn
 * Date: 2008-2-25
 * Time: 16:40:06
 */
public class ResourceDispatcher {
    private static HashMap<String,JPanel> panelHolder;

    public ResourceDispatcher(){
        Object panelHolderObject = ApplicationResource.get(SysConstants.PANEL_WORD);
        if(panelHolderObject == null){
            panelHolder = new HashMap<String, JPanel>();
            ApplicationResource.put(SysConstants.PANEL_WORD,panelHolder);
        }else{
            panelHolder = (HashMap<String,JPanel>)panelHolderObject;
        }
    }

    public int registerPanel(String panelName, JPanel panel){
        panelHolder.put(panelName,panel);
        return 0;
    }

    public JPanel getPanel(String panelName) throws Exception{
        JPanel panel = panelHolder.get(panelName);
        if(panel == null) throw new Exception("Panel with name : "+panelName+" was found not registered!");
        return panel;
    }
}
